package cn.com.edu.nju.ecrec.dataProcess;

import java.io.*;
import java.util.Date;

import javax.persistence.*;

import cn.com.edu.nju.ecrec.model.*;
import cn.com.edu.nju.ecrec.util.JPAFactory;

public class EventExtraction {
	static void processEvent() {
		try {
			BufferedReader br = new BufferedReader(new FileReader(new File(
					"event.txt")));

			EntityManager em = JPAFactory.getManager();
			String line = br.readLine();
			while (line != null) {
				em.getTransaction().begin();
				Event evt = new Event();
				evt.setUserID(line);
				evt.setPosition(br.readLine());
				line = br.readLine();
				if(line.equals("null")||line.equals(""))
					evt.setTime(null);
				else
					evt.setTime(new Date(Long.parseLong(line)));
				evt.setPage(br.readLine());
				evt.setType(br.readLine());
				evt.setInputValue(br.readLine());
				em.persist(evt);
				em.getTransaction().commit();
				br.readLine();
				line = br.readLine();
			}
			em.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		processEvent();
	}
}